from gensim.models import Word2Vec

# 加载训练好的模型
model = Word2Vec.load('word2vec.model')
# 使用训练好的此向量对指定的词进行相关性比较
print(f"①'问候'与'祝愿'的相关性: {model.wv.similarity('问候', '祝愿')}")
print(f"②'生机'与'希望'的相关性: {model.wv.similarity('生机', '希望')}")
print()

# 使用训练好的词向量选出与指定词最相似的5个词
words = model.wv.most_similar(positive=['和平'], topn=5)
print(f"①与'和平'相似: ")
for word in words:
    print(word)
words = model.wv.most_similar(positive=['信心'], topn=5)
print(f"②与'信心'相似: ")
for word in words:
    print(word)
print()

# 使用训练好的词向量选出与指定词类比最相似的5个词
words = model.wv.most_similar(positive=['和平', '安宁'], negative=['生机'], topn=5)
print('①')
for word in words:
    print(word)
words = model.wv.most_similar(positive=['稳定', '祝愿'], negative=['奋斗'], topn=5)
print(f"②")
for word in words:
    print(word)
